package org.loofer.uikit;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;

public class OverlapLayout extends ViewGroup {
    public OverlapLayout(Context context) {
        super(context);
    }

    public OverlapLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public OverlapLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int maxWidth = 0;
        int maxHeight = 0;
        int count = getChildCount();
        for (int i = 0; i < count; i++) {
            View child = getChildAt(i);
            if (!(child == null || child.getVisibility() == 8)) {
                child.measure(widthMeasureSpec, heightMeasureSpec);
                int childWidth = child.getMeasuredWidth();
                int childHeight = child.getMeasuredHeight();
                if (maxWidth < childWidth) {
                    maxWidth = childWidth;
                }
                if (maxHeight < childHeight) {
                    maxHeight = childHeight;
                }
            }
        }
        maxHeight += getPaddingTop() + getPaddingBottom();
        setMeasuredDimension(resolveSize(Math.max(maxWidth + (getPaddingLeft() + getPaddingRight()), getSuggestedMinimumWidth()), widthMeasureSpec), resolveSize(Math.max(maxHeight, getSuggestedMinimumHeight()), heightMeasureSpec));
    }

    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        int parentLeft = getPaddingLeft();
        int parentRight = (right - left) - getPaddingRight();
        int parentTop = getPaddingTop();
        int parentBottom = (bottom - top) - getPaddingBottom();
        int count = getChildCount();
        for (int i = 0; i < count; i++) {
            View child = getChildAt(i);
            if (!(child == null || child.getVisibility() == 8)) {
                child.layout(parentLeft, parentTop, parentRight, parentBottom);
            }
        }
    }

    protected LayoutParams generateDefaultLayoutParams() {
        return new LayoutParams(-1, -1);
    }
}
